package com.example.ttt.functions;

import com.example.ttt.controller.GUIHome;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.swing.*;

/*
* 登录按钮登录事件
* */

@Component
@Slf4j
public class Button_Login {

    @Autowired
    private GUIHome guiHome;

    public void login_bt_action(JTextField user_tf, JPasswordField password_tf, JFrame jFrame) {

        //获取登录的用户名和密码
        String username = user_tf.getText().toString();
        String password = String.valueOf((password_tf.getPassword()));
        log.info("登录的用户名为:{}    登录用户密码为:{}",username,password);

        // 断言 account 并打开 home 页面
        if(true) {
            log.info("登录成功");
            guiHome.home();
            jFrame.dispose();
            guiHome.init();
        } else {
            //登录失败弹出提示框
            System.out.println("登录失败");
            JOptionPane.showConfirmDialog(jFrame,"请检查用户名或密码","登录提示",2,1);
        }

    }
}
